﻿using System.Collections.Generic;
using System.Linq;
using WroxBlog.Models.Interfaces;

namespace WroxBlog.Models.Implementations
{
    public class CategoryRepository : ICategoryRepository
    {
        #region ICategoryRepository Members

        public CategoryCollection GetCategories()
        {
            WroxBlogDataContext context = new WroxBlogDataContext();

            List<Category> categories = context.Categories.ToList<Category>();

            return GetCategoriesCollection(categories);
        }

        #endregion

        #region Private Methods

        private CategoryCollection GetCategoriesCollection
            (List<Category> categories)
        {
            CategoryCollection collection = new CategoryCollection();
            collection.AddRange(categories);
            return collection;
        }

        #endregion
    }
}
